package single;

import java.util.Random;

import GUI.lafenetre;
import GUI.lafenetre.*;


public class singlethreaded {

    public int progress;
    private lafenetre something;
    
    //////////////CONSTRUCTOR//////////////
    public singlethreaded(lafenetre something){
    	this.something = something;
    }
    
	public double MonteCarloStandardOption(String CallPutFlag, double S, 
			double X, double T, double r, double b, double v, int nSteps, int nSimulations)
	{

	      //Variables
		  int i,j,z;
		  double st;
		  double dt = T / nSteps;
		  double Drift = (b - v*v / 2) * dt;
		  double vSqrdt = v * java.lang.Math.sqrt(dt);;
	      Random rand = new Random();
		  double Sum = 0;
		  
		  double MonteCarloStandardOption;
	      
	      //Check if this is a call or a put (c or p)
		  if ("c".equals(CallPutFlag)) z=1;
	      else if ("p".equals(CallPutFlag))z=-1;
	      else z=0;
	      
	      //Calculate
	      for(i=0;i<nSimulations;i++){
	          st = S;
	          
	          for(j=0;j<nSteps;j++){
	              st = st * Math.exp(Drift + vSqrdt * rand.nextGaussian());
	          }
	          Sum += Math.max(z*(st-X), 0);
	      }
	      MonteCarloStandardOption = Math.exp( -r * T) * (Sum / nSimulations);
	      return MonteCarloStandardOption;
	}
	
}
